package com.cy.bus.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;

/**
 * 运行界面
 * @author CY
 *
 */
public class LaunchActivity extends Activity implements Runnable {

	private final Handler h = new MyHandler();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 去掉窗口标题
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 全屏显示
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		//加载界面
		setContentView(R.layout.activity_launch);
		//开启线程
		new Thread(this).start();
	}

	/**
	 * 线程
	 * 调用Handler对象处理。
	 */
	@Override
	public void run() {
		try {
			Thread.sleep(2000);
			Message msg = new Message();
			msg.what = 0x1233;
			h.sendMessage(msg);
			this.finish();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Handler类 
	 * 用来加载数据，切换Activity(CHCFActivity)。
	 * @author CY
	 *
	 */
	@SuppressLint("HandlerLeak")
	private final class MyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			if(msg.what == 0x1233) {
				Intent intent = new Intent(getApplicationContext(), MainActivity.class);
		    	startActivity(intent);
			}
		}
	}

}